fix: Enterprise WeChat docking sub application cannot output thinking process#2489
fix: Enterprise WeChat docking sub application cannot output thinking process#2489shaohuzhang1 merged 1 commit intomainfrom
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| zip(answer_list, range(len(answer_list)))} | ||
| _write_context(node_variable, workflow_variable, node, workflow, answer, reasoning_content) | ||
|
|
||
|
|
There was a problem hiding this comment.
Here are the identified issues and potential improvements:
Issues:
-
Variable Access:
- The line
node_variable['application_node_dict']is accessing a variable namedresponse, which does not exist at that stage of the function execution. This will likely raise an error.
- The line
-
Answer List Handling:
- The line
${{answer.get('real_node_id')contains interpolation syntax, but it's missing the opening brace{. - The logic to update
node_variable['application_node_dict']seems incorrect because both keys ("real_node_id"and"index") should be included in each entry.
- The line
-
Function Parameters:
- The last parameter passed to
_write_context()isworkflow, but there is no such parameter defined in the original code snippet you provided.
- The last parameter passed to
Potential Improvements:
-
Correct Variable Name:
- Ensure that the
responsevariable is correctly referenced if needed or removed if unnecessary.
- Ensure that the
-
Fix Template Syntax:
- Replace
${{answer.get('real_node_id')}}with simplyanswer.get('real_node_id').
- Replace
-
Re-evaluate Data Structure:
- Review what data structure is intended for
node_variable['application_node_dict']. If you mean to store different types of data under'actual_node_id', adjust the dictionary accordingly.
- Review what data structure is intended for
-
Parameter Correctness:
- Double-check that all parameters passed to
_write_context()match those expected, and add any necessary parameters that might have been omitted from the previous version.
- Double-check that all parameters passed to
-
Error Handling:
- Consider adding error handling to manage cases where certain fields like
'prompt_tokens', 'content', ..., 'might not always be available in theresponse.
- Consider adding error handling to manage cases where certain fields like
Without additional context on how these variables interact, some further refinement may be required.
| answer_list=other_params.get('answer_list', ""), | ||
| message=ChatCompletionMessage(role='assistant', content=content))], | ||
| created=datetime.datetime.now().second, model='', object='chat.completion', | ||
| usage=CompletionUsage(completion_tokens=completion_tokens, |
There was a problem hiding this comment.
The provided code snippet seems mostly correct, but there are a few minor adjustments and clarifications that can be made to ensure it works as intended:
-
Use of
getmethod correctly: In Python dictionaries, using theget()method with a default parameter (other_params.get('reasoning_content', "")) will handle cases where 'reasoning_content' is not present inother_params. This prevents a potential KeyError. -
Correct import statement for datetime module: Ensure you have imported the
datetimemodule at the beginning of your file if it's not already imported. The current line imports from bothpandasandpyarrow, so I assumedatetimeis used elsewhere; however, here we just need to make sure it's available. -
Consistency in handling None values: When accessing dictionary keys, always check for their existence before proceeding to access them to avoid NoneType errors.
Here’s the code with these points addressed:
import datetime
def to_block_response(self, chat_id, chat_record_id, content, is_end, completion_tokens, other_params):
# Using get() to safely retrieve reasoning_content from other_params
reasoning_content = other_params.get('reasoning_content', "")
# Similarly, use get() to safely retrieve answer_list from other_params
answer_list = other_params.get('answer_list', [])
data = ChatCompletion(
id=chat_record_id,
choices=[
BlockChoice(
finish_reason='stop',
index=0,
chat_id=chat_id,
reasoning_content=reasoning_content,
- answer_list answer_list,
message=ChatCompletionMessage(role='assistant', content=content)
)
],
created=datetime.datetime.now().timestamp(),
model='',
object='chat.completion',
usage=CompletionUsage(completion_tokens=completion_tokens)
)
# Example usage with an empty list for completeness
example_other_params = {}
to_block_response("id_123", "record_1", "Hello!", True, 20, example_other_params)This should prevent any runtime errors related to missing keys in the other_params dictionary and maintain proper consistency in value fetching.
fix: Enterprise WeChat docking sub application cannot output thinking process